package com.nisco.dms.repository;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;

import com.nisco.dms.entity.Menu;


/**
 * 
 * @author joey
 *
 */
public interface MenuDao extends JpaRepository<Menu, String> {
			
	Page<Menu> findByParentId(String fatherId, Pageable pageable);
	
	Page<Menu> findByParentIdAndStrNameContaining(String fatherId, String strName, Pageable pageable);
	
	@QueryHints(value={
			@QueryHint(name="org.hibernate.cacheable",value="true"),
			@QueryHint(name="org.hibernate.cacheRegion",value="com.nisco.dms.entity")
		}
	)
	@Query("from Menu m order by m.intPriority ASC")
	List<Menu> findAllWithCache();
	
	@Query("from  Menu m where m.id=?1 ")
	Menu findOne(String id);//根据id查找实体 
	
	@Modifying
	@Query(value="delete from Ds_Menu  where programId=?1 and fatherId=?2",nativeQuery = true)
	public void deleMenuByInfo(String programId,String fatherId);
	
	Menu findByProgramId(String programId);//根据programid查找实体 
}
